//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Files.Components;

namespace CommunityServer.Files.Controls
{
	/// <summary>
	/// Summary description for TagBreadCrumb.
	/// </summary>
	public class TagBreadCrumb : CommunityServer.Controls.TagBreadCrumb
	{
		protected override void CreateChildControls() 
		{
			if (this.ShowHome)
			{
				this.ShowHome = false;
				crumbs.Enqueue(GetAnchor(ResourceManager.GetString("home"), FileGalleryUrls.Instance().Home));
		
				Group group = Folders.GetFolderGroup(this.Folder.GroupID, true, false);
				crumbs.Enqueue(GetAnchor(group.Name, FileGalleryUrls.Instance().ViewFolderGroup(group.GroupID)));

				crumbs.Enqueue(GetAnchor(this.Folder.Name, FileGalleryUrls.Instance().ViewFolder(this.Folder.ApplicationKey)));
			}

			base.CreateChildControls();
		}

		protected override string GetTagUrl()
		{
			return FileGalleryUrls.Instance().TagsHome(this.Folder.ApplicationKey);
		}

		protected override string GetTagUrl(string[] tagsPath)
		{
			return FileGalleryUrls.Instance().TagsBrowser(this.Folder.ApplicationKey, tagsPath);
		}

		protected override string GetTagRssUrl(string[] tagsPath)
		{
			if (this.Folder.EnableTagsRss)
			{
				CSContext context = CSContext.Current;
				bool isAvailableToPublic = Permissions.ValidatePermissions(Folder, Permission.View, Users.GetAnonymousUser(true));

				if (isAvailableToPublic)
					return FileGalleryUrls.Instance().Rss(this.Folder.ApplicationKey, tagsPath, true);
				else if (context.SiteSettings.EnableSecureSyndication)
					return SiteUrls.FormatUrlWithUserNameToken(FileGalleryUrls.Instance().Rss(this.Folder.ApplicationKey, tagsPath, true), context.User, true);
			}

			return null;
		}

		private Folder folder = null;
		public virtual Folder Folder
		{
			get
			{
				if (folder == null)
				{
					folder = Folders.GetFolder(csContext.ApplicationKey);
					Permissions.AccessCheck(folder,Permission.View,csContext.User);
				}

				return folder;
			}
		}

	}
}
